<?php
class Business {
  private $theApp;

  function __construct($appHandle) {
    $this->theApp = $appHandle;
  }
  
  function renderWelcome() {
    $this->theApp->presentation->welcome("Welcome to the ST1 DaBa Project Degiorgi / Yuruz", 
                                         $this->theApp->data->getOverAllStatsOffer(),
                                         $this->theApp->data->getOverAllStatsInvoice(),
                                         $this->theApp->data->getWorkItems(),
                                         $this->theApp->data->getCustomers(),
                                         $this->theApp->data->getMinMaxDates());
  }
  
  function generateReport() {
    $this->theApp->presentation->renderReport("Report",
                                              $this->theApp->data->getWorkItems(),
                                              $this->theApp->data->getCustomers(),
                                              $this->theApp->data->getReportData(),
                                              $this->theApp->data->getTotalSum());
  }

  function makeSHA256Hash($string) {
    return hash("sha256",$string);
  }
  
  function forwardBrowser($dest) {
    header("Location: " . $dest . "\n\n");
  }
    
  function destroySession() {
    session_destroy();
    $this->theApp->user = null;
  }

  function sendMail($subject,$mailtext,$recipient) {
//    ini_set('sendmail_from', $this->theApp->config->mailSender);
    ini_set('sendmail_from', $this->theApp->user->EMail);
//    echo $this->theApp->config->mailSender . "\n";
    $header    = "From: ". $this->theApp->user->Vorname . " " . $this->theApp->user->Name . " <" . $this->theApp->user->EMail . ">\r\n"; //optional headerfields
//    echo $recipient->EMail, $subject, $mailtext, $header;
    mail($recipient->EMail, $subject, $mailtext, $header);
  }
    
  function errorHandler($message = "") {
    $this->theApp->presentation->errorHandler($message);
    exit(0); // very not_so_nice just exiting 
  }

  public function __toString() {
    return "A hearty 'Hello' from Business Layer.";
  }
}
